package com.hjn.springboot.springbootservlet.servlet;

import com.hjn.springboot.springbootservlet.entity.User;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;

/**
 * @author: huaijn
 * @create: 2022/5/10 20:01
 * @description: todo
 **/
public class MyServlet03 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        User user = (User) session.getAttribute("user");
        if (user == null) {
            user = new User("jsdlf0se3", "zhangsan", 12);
            session.setAttribute("user", user);
        }
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getMethod();
        Enumeration<String> headerNames = req.getHeaderNames();
        String header = null;
        while (headerNames.hasMoreElements()) {
            header = headerNames.nextElement();
            req.getHeader(header);
        }
        Enumeration<String> parameterNames = req.getParameterNames();
        while (parameterNames.hasMoreElements()) {
            String key = parameterNames.nextElement();
            String value = req.getParameter(key);
            System.out.println("参数名是：" + key + " ;参数值是" + value);
        }
        resp.setContentType("text/json;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        writer.println("成功了");

    }

    public static void main(String[] args) {

        List<String> list1 = new ArrayList<String>();
        list1.add("A");
        list1.add("B");

        List<String> list2 = new ArrayList<String>();
        list2.add("B");
        list2.add("C");
        list2.retainAll(list1);
        System.out.println(list2);

    }
}
